package com.lqk.nio.filechannel;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NIOFileChannel03 {
    public static void main(String[] args) throws Exception {
        FileInputStream fileInputStream = new FileInputStream("D:\\Progrom Files\\java8new\\netty\\file\\file01.txt");
        FileChannel inputStreamChannel = fileInputStream.getChannel();
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\Progrom Files\\java8new\\netty\\file\\file02.txt");
        FileChannel outputStreamChannel = fileOutputStream.getChannel();
        ByteBuffer byteBuffer = ByteBuffer.allocate(5);

        while (true){
            byteBuffer.clear();
            int read = inputStreamChannel.read(byteBuffer);
            if (read==-1){
                break;
            }
            byteBuffer.flip();
            while (byteBuffer.hasRemaining()){
                outputStreamChannel.write(byteBuffer);
            }
        }

        fileInputStream.close();
        fileOutputStream.close();
    }
}
